package com.ruoyi.yzchu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yzchu.domain.YzcOrderItem;
import com.ruoyi.yzchu.service.IYzcOrderItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单明细（从）Controller
 * 
 * @author ruoyi
 * @date 2025-04-06
 */
@RestController
@RequestMapping("/system/item")
public class YzcOrderItemController extends BaseController
{
    @Autowired
    private IYzcOrderItemService yzcOrderItemService;

    /**
     * 查询订单明细（从）列表
     */
    @PreAuthorize("@ss.hasPermi('system:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(YzcOrderItem yzcOrderItem)
    {
        startPage();
        List<YzcOrderItem> list = yzcOrderItemService.selectYzcOrderItemList(yzcOrderItem);
        return getDataTable(list);
    }

    /**
     * 导出订单明细（从）列表
     */
    @PreAuthorize("@ss.hasPermi('system:item:export')")
    @Log(title = "订单明细（从）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YzcOrderItem yzcOrderItem)
    {
        List<YzcOrderItem> list = yzcOrderItemService.selectYzcOrderItemList(yzcOrderItem);
        ExcelUtil<YzcOrderItem> util = new ExcelUtil<YzcOrderItem>(YzcOrderItem.class);
        util.exportExcel(response, list, "订单明细（从）数据");
    }

    /**
     * 获取订单明细（从）详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:item:query')")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") Long itemId)
    {
        return success(yzcOrderItemService.selectYzcOrderItemByItemId(itemId));
    }

    /**
     * 新增订单明细（从）
     */
    @PreAuthorize("@ss.hasPermi('system:item:add')")
    @Log(title = "订单明细（从）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YzcOrderItem yzcOrderItem)
    {
        return toAjax(yzcOrderItemService.insertYzcOrderItem(yzcOrderItem));
    }

    /**
     * 修改订单明细（从）
     */
    @PreAuthorize("@ss.hasPermi('system:item:edit')")
    @Log(title = "订单明细（从）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YzcOrderItem yzcOrderItem)
    {
        return toAjax(yzcOrderItemService.updateYzcOrderItem(yzcOrderItem));
    }

    /**
     * 删除订单明细（从）
     */
    @PreAuthorize("@ss.hasPermi('system:item:remove')")
    @Log(title = "订单明细（从）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable Long[] itemIds)
    {
        return toAjax(yzcOrderItemService.deleteYzcOrderItemByItemIds(itemIds));
    }
}
